#encoding: utf-8

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import database
import pymysql

app = Flask(__name__)
# app.config.from_object(database)
# db = SQLAlchemy(app)
# db.create_all()

config = {
          'host':'172.19.0.3',
          'port':3306,
          'user':'root',
          'password':'xiaokang',
          'db':'flask',
          'charset':'utf8',
          'cursorclass':pymysql.cursors.DictCursor,
          }
db = pymysql.connect(**config)
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

# 使用 execute()  方法执行 SQL 查询
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()

print("Database version : %s " % data)

# 关闭数据库连接
db.close()


@app.route('/')
def index():
    return data['VERSION()']

if __name__ == '__main__':
    app.run(host="0.0.0.0",debug=True)